<?php

namespace app\admin\validate;

use think\Validate;

class StoreValidate extends Validate
{
    protected $rule = [
        'store_name' => 'require|unique:store|max:100',
        'store_logo' => 'require',
        'nickname' => 'max:30',
        'username' => 'require|unique:admin|max:30',
        'password' => 'require|confirm',
        'company_name' => 'require|max:100',
        'business_license' => 'require',
        'legal_person' => 'require|max:30',
        'legal_phone' => 'require|mobile',
        'id_number' => 'require|idCard',
        'id_card_front' => 'require',
        'id_card_reverse' => 'require',
        'company_address' => 'require',
        'status' => 'require|in:0,1'
    ];


    protected $message = [
        'id.require' => '非法请求',
        'id.integer' => '非法请求',
        'store_name.require' => '店铺名称不能为空!',
        'store_name.unique' => '店铺名称已存在!',
        'store_name.max' => '店铺名称最多50个字符!',
        'store_logo.require' => '请上传店铺logo',
        'username.require' => '请输入登录账号',
        'username.unique' => '登录账号已存在',
        'password.require' => '账号密码不能为空',
        'password.confirm' => '两次输入账号密码不一致!',
        'company_name.require' => '请输入公司名称',
        'business_license.require' => '请上传营业执照!',
        'legal_person.require' => '请输入法人姓名',
        'legal_phone.require' => '请输入法人手机号!',
        'legal_phone.mobile' => '请输入正确的法人手机号', 
        'id_number.require' => '请输入法人身份证号!',
        'id_number.idCard' => '请输入正确的法人身份证号!',
        'id_card_front.require' => '请上传法人身份证正面!',
        'id_card_reverse.require' => '请上传法人身份证发面',
        'company_address.require' => '请输入公司地址!',
        'status.in' => '无效的状态值!'
    ];

    public function sceneSwitch()
    {
        return $this->only(['id','status'])
                    ->append('id', 'require|integer');
    }

    public function sceneEdit()
    {
    	return $this->only(['id','store_name','store_logo','company_name','business_license','password','legal_person','legal_phone',
                    'id_number','id_card_front','id_card_reverse','company_address','status'])
                    ->append('id', 'require|integer')
                    ->remove('username')
                    ->remove('password','require');
    }   
}